<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function arr(target, maxDoubles) {
      let res = 0
      while (maxDoubles > 0 && target > 1) {
        if (target % 2 === 1) { target-- }
        else { target >>= 1, maxDoubles-- }
        res++
      }
      return res + target - 1
    };
    console.log(arr(target = 19, maxDoubles = 2));
  </script>
</body>

</html>